<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML >
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>添加学生</title>
    
	<meta http-equiv="pragma" content="no-cache">
	<meta http-equiv="cache-control" content="no-cache">
	<meta http-equiv="expires" content="0">    
	<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
	<meta http-equiv="description" content="This is my page">
	<%@include file="/pages/head/head.jsp" %>
         <%@include file="/pages/head/foot.jsp" %>
  </head>
 
  <body>
   
  
   <div id="wrapper">
        <!-- 左边菜单 -->
         <%@include file="/pages/left/leftmenu.jsp" %>

        <div id="page-wrapper" class="gray-bg dashbard-1">
             <!-- 引入top菜单 -->
              <%@include file="/pages/left/topmenu.jsp" %>
            
            <!--左边内容开发，开始  -->
              <div class="row wrapper border-bottom white-bg page-heading">
                <div class="col-lg-10">
                    <h2>学生资料</h2>
                    <ol class="breadcrumb">
                        <li>
                            <a href="index.html">主页</a>
                        </li>
                        <li>
                            <a>学生资料</a>
                        </li>
                        <li>
                            <strong>添加学生资料</strong>
                        </li>
                    </ol>
                </div>
                <div class="col-lg-2">

                </div>
            </div>
            <div class="wrapper wrapper-content animated fadeInRight">
                
                <div class="row">
                    <div class="col-lg-14">
                        <div class="ibox float-e-margins">
                            <div class="ibox-title">
                                <h5>添加学生资料</h5>
                                <div class="ibox-tools">
                                    <a class="collapse-link">
                                        <i class="fa fa-chevron-up"></i>
                                    </a>
                                </div>
                            </div>
                            <div class="ibox-content">
                                <form class="form-horizontal m-t" id="students" name="students" method="post" >
                                
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">学生编号：</label>
                                        <div class="col-sm-8">
                                            <input id="stuno" name="stuno" value="${students.stuno }" maxlength="30"  class="form-control" type="text">
                                            <input id="stuId" name="stuId" value="${students.stuId }" maxlength="30"  class="form-control" type="hidden">
                                            <input id="password" name="password" value="${students.password }" maxlength="30"  class="form-control" type="hidden">
                                            <input id="schoolId" name="schoolId" value="${students.schoolId }" maxlength="30"  class="form-control" type="hidden">
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">学生名称：</label>
                                        <div class="col-sm-8">
                                            <input id="stuname" name="stuname" value="${students.stuname }"  maxlength="30" class="form-control" type="text">
                                        </div>
                                    </div>
                                   
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">性别：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="sex" id="sex">
                                            	<option value="0">--请选择--</option>
                                                <option value="1" >男</option>
                                                <option value="2" >女</option>
                                            </select>
                                        </div>
                                    </div>
                                    
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">班级：</label>
                                        <div class="col-sm-8">
                                            <select class="form-control m-b" name="classId" id="classId">
                                            <option value="0">--请选择--</option>
                                            <c:forEach items="${requestScope.classAll }" var="eachClass">  
                            						<option value="${eachClass.classId }">${eachClass.classCode } - ${eachClass.className }</option>
                                            </c:forEach>  
                                            </select>
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">手机号码：</label>
                                        <div class="col-sm-8">
                                            <input id="phone" name="phone" value="${students.phone }" class="form-control" type="text" aria-required="true" aria-invalid="true" class="error">
                                        </div>
                                    </div>
                                    
                                    <div class="form-group">
                                        <label class="col-sm-3 control-label">邮箱：</label>
                                        <div class="col-sm-8">
                                            <input type="text" id="email" name="email" value="${students.email }" class="form-control mail" />
                                            <script>
												$("#email").emailMatch();
											</script>
                                        </div>
                                    </div>
                                    <div class="form-group">
                                        <div class="col-sm-8 col-sm-offset-3">
                                            <button class="btn btn-primary" id="submitbutton" onclick="checkFyFhSubmit()" type="button">提交</button>
                                        </div>
                                    </div>
                                </form>
                            </div>
                        </div>
                    </div>
                </div>

            </div>
         

        </div>
    </div>
    
    
      <!-- simditor -->

    <script>
 
    
	$(function(){  
		  
		 //文本框只能输入数字，并屏蔽输入法和粘贴  
		 $.fn.numeral = function() {     
		            $(this).css("ime-mode", "disabled");     
		            this.bind("keypress",function(e) {     
		            var code = (e.keyCode ? e.keyCode : e.which);  //兼容火狐 IE      
		              /*   if(!$.browser.msie&&(e.keyCode==0x8))  //火狐下不能使用退格键     
		                {     
		                     return ;     
		                    }   */   
		                    return code >= 48 && code<= 57;     
		            });     
		            this.bind("blur", function() {     
		                if (this.value.lastIndexOf(".") == (this.value.length - 1)) {     
		                    this.value = this.value.substr(0, this.value.length - 1);     
		                } else if (isNaN(this.value)) {     
		                    this.value = "";     
		                }     
		            });     
		            this.bind("paste", function() {     
		                var s = clipboardData.getData('text');     
		                if (!/\D/.test(s));     
		                value = s.replace(/^0*/, '');     
		                return false;     
		            });     
		            this.bind("dragenter", function() {     
		                return false;     
		            });     
		            this.bind("keyup", function() {     
		            if (/(^0+)/.test(this.value)) {     
		                this.value = this.value.replace(/^0*/, '');     
		                }     
		            });     
		        };    
		        //调用文本框的id  
		  $("#phone").numeral();   
		        
		  $("#sex option[value='${students.sex}']").attr("selected",true);
		  $("#classId option[value='${students.classId}']").attr("selected",true);
		  
		});  
    
        
        /** 表单验证  **/
    	function validateForm(){
    		if($("#stuno").val()==""){
    			alert("学生编号不可以为空");
    			return false;
    		}
    		if($("#stuname").val()==""){
    			alert("学生名称不可以为空");
    			return false;
    		}
    		
    		if($("#sex").val()=="0"){
    			alert("请选择性别");
    			return false;
    		}
    		if($("#classId").val()=="0"){
    			alert("请选择班级");
    			return false;
    		}
    		
    		
    		return true;
    	}
    	
    	 function checkFyFhSubmit(){
    		$.ajax({
				type:"POST",
				url:"${pageContext.request.contextPath}/student/updateStudents.do",
				data:$("#students").serialize(),
				async: true,
				dataType: "text", 
	  			error: function(request) {alert("添加信息失败！"+request.responseText);},
				success:function(data){
					var result=String($.trim(data));
					if(result == "succ"){
						alert("操作成功");
					}
					else{
						alert("操作失败");
					}
					
				}
			});
		//return true;
    	} 
    	
    	/* function checkFyFhSubmit(){
    		 var url="${pageContext.request.contextPath}/classrequire/addClassrequire.do";
        	var param=$("#classrequire").serialize();
        	$.post(url,param,function(data){
        		if(data=="succ"){
        			alert("保存成功");
        			location.reload();
        		}else{
        			alert("保存失败,请再次保存！");
        		}

        	}); 
    	} */
    </script>
  </body>
</html>
